---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
---
```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)
library(flexdashboard)
```
```{r}
data("ny_noaa")
ny_noaa =
ny_noaa |>
drop_na() |>
mutate(
tmax = as.numeric(tmax),
tmin = as.numeric(tmin)
) |>
mutate(avg_t = (tmax + tmin) / 2)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
ny_noaa |>
filter(year(date) == 2002, month(date) %in% 6:9) |>
plot_ly(x = ~tmin, y = ~tmax, text = ~date, color = ~factor(month(date)),
alpha = .5, type = "scatter", mode = "markers", colors = "viridis") |>
layout(title = "tmax vs tmin (June to September 2002)",
xaxis = list(title = "tmax"),
yaxis = list(title = "tmin"),
coloraxis = list(title = "Month"))
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
ny_noaa |>
plot_ly(y = ~tmax, type = "box", name = "tmax") |>
add_trace(y = ~tmin, type = "box", name = "tmin") |>
layout(title = "tmax and tmin Distribution",
yaxis = list(title = "Temperature"))
```
### Chart C
```{r}
ny_noaa |>
filter(year(date) %in% 2001:2010) |>
group_by(year(date)) |>
summarize(avg_snow = mean(snow, na.rm = TRUE)) |>
plot_ly(x = ~year, y = ~avg_snow, type = 'bar', name = 'Snowfall') |>
layout(title = "Average Snowfall (2001-2010)",
xaxis = list(title = "Year"),
yaxis = list(title = "Average Snowfall"))
```